package com.rdk.wechat.util;

import java.util.List;

public class StringUtil {
	/**
     * 判断字符串是否为空
     * 
     * @param strVal string
     * @return true 为空 false 不为空
     */
    public static boolean isEmpty(String strVal) {
        return strVal == null || trim(strVal).equals("");
    }
    
    public static String ListToString(List<String> list){
    	
    	String str = "";
    	for (String string : list) {
    		str += "\"" + string+"\",";
		}
    	str = str.substring(0,str.length()-1); 
    	
    	return str;
    }
    
    public static String trimBracket(String strVal){
    	String strTemp = strVal.substring(0,strVal.length()-1);
    	return strTemp.substring(1, strTemp.length()); 
    }
    
    /**
     * 去除左右边全、半角空格
     * 
     * @param strValue 字符串
     * @return String 去除左右边全、半角空格字符串
     */
    public static String trim(String strValue) {

        if ((strValue != null) && (!strValue.equals(""))) {
            StringBuffer sb = new StringBuffer();
            StringBuffer sb1 = new StringBuffer();
            String strRet = "";
            sb.append(rTrim(strValue));
            // 反转后去掉右空格
            strRet = rTrim(sb.reverse().toString());
            sb1.append(strRet);
            strRet = sb1.reverse().toString();
            return strRet.trim();
        } else {
            return "";
        }
    }
    
    /**
     * 去除右边全半角空格
     * 
     * @param strValue String
     * @return String String
     */
    private static String rTrim(String strValue) {

        if ((strValue != null) && (!strValue.equals(""))) {
            char[] cValue = strValue.toCharArray();
            int nCur = 0;

            for (int i = cValue.length - 1; i > -1; i--) {
                if ((cValue[i] != '\u0020') && (cValue[i] != '\u3000')) {
                    nCur = i;
                    break;
                }
            }

            if ((nCur == 0) && ((cValue[0] == '\u0020') || (cValue[0] == '\u3000'))) {
                return "";
            }

            return strValue.substring(0, nCur + 1);
        } else {
            return "";
        }
    }
}
